package com.sch.www.sys.services.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.sch.www.common.base.BaseServicesSimpleImp;
import com.sch.www.sys.orm.dao.manual.RoleMapper;
import com.sch.www.sys.orm.entity.manual.Role;
import com.sch.www.sys.orm.entity.manual.RoleExample;
import com.sch.www.sys.services.RoleServices;
import com.sch.www.sys.services.AccountToRoleServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleServicesImpl extends BaseServicesSimpleImp<Role, RoleExample, RoleMapper, RoleServices> implements RoleServices {

    @Autowired
    AccountToRoleServices accountToRoleServices;

    @Override
    protected String getTableName() {
        return null;
    }

    @Override
    protected RoleExample getExampleNewInstance() {
        return new RoleExample();
    }


    @Override
    public List<Role> selectByAccountId(String... accountIds) {

        List<String> roleIdList = getCurrentProxy().selectIdByAccountId(accountIds);
        if (CollectionUtils.isEmpty(roleIdList)) {
            return new ArrayList<>();
        } else {
            RoleExample example = new RoleExample();
            example.createCriteria().andIdIn(roleIdList);
            return getMapper().selectByExample(example);
        }
    }

    @Override
    public List<String> selectIdByAccountId(String... accountIds) {
        return accountToRoleServices.selectRoleIdByAccountId(accountIds);
    }

    @Override
    public List<Role> selectAll() {
        return getMapper().selectByExample(null);
    }

}
